﻿<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>忘记密码</title>
    <style type="text/css">
        .header
        {
            height:50px;
            background-color:dodgerblue;
            color: white;
            font-size: larger;
            font-family: "微软雅黑";
            text-indent: 2em;
            line-height:50px;
        }
        .passwd_table
        {
            width: 400px;
            position: absolute;
            top:50%;
            left:50%;
            transform: translate(-50%,-60%);
            border-collapse:separate ;
            border-spacing: 10px;
        }
        .submit_button
        {
            text-align: center;
        }
        .passwd_info
        {
            outline:none;
            -webkit-appearance:none;
            border-radius: 4px;
            border:1px solid #c8cccf
        }
    </style>
</head>
<body>
<div class="header">云笔记</div>
<form action="" method="get" name="passwd">
    <table class="passwd_table">
        <tr>
            <td><label for="user_text">用户名:</label></td>
            <td><input type="text" class="passwd_info" id="user_text"><span id="s4"></span></td>
        </tr>
        <tr>
            <td><label for="new_passwd">新密码:</label></td>
            <td><input type="password" class="passwd_info" id="new_passwd"></td>
        </tr>
        <tr>
            <td><label for="passwd_confirm">确认密码:</label></td>
            <td><input type="password" class="passwd_info" id="passwd_confirm"><span id="s3"></span></td>
        <tr><td></td><td><input type="button" id="send_code" value="发送验证码到邮箱"></td></tr>
        <tr>
            <td><label for="iden_code">验证码:</label></td>
            <td><input type="password" class="passwd_info" id="iden_code"></td>
        </tr>
        <tr>
            <td colspan="3"><div class="submit_button"><input type="button" id="sub" value="提交"></div></td>
        </tr>
    </table>
</form>
<script>
    var user=document.getElementById("user_text");
    var p1=document.getElementById("new_passwd");
    var p2=document.getElementById("passwd_confirm");
    var iden=document.getElementById("iden_code");
    var sub=document.getElementById("sub");
    var send_code=document.getElementById("send_code");
    p2.onblur=function(){
        if(p1.value!=p2.value)
        {
            document.getElementById("s3").innerText="两次密码输入不一致！";
            p2.value="";
            p2.focus();
            flag=false;
        }
        else
        {
            document.getElementById("s3").innerText="";
        }
    }
    sub.onclick=function(){
//        alert("hello");
        var request=new XMLHttpRequest();
        request.open("POST","/i/noteuser/noteUser/modify_password",true);
        request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        var message="userName="+user+"&password="+p1+"&identifycode="+iden;
        request.onreadystatechange=function(){
            if(request.readyState==4)
            {
                if(request.status==200)
                {
                    var data=JSON.parse(request.responseText);
                    if(data.result==1)
                    {
                        alert("修改成功！")
                        window.location.href="Main.jsp";
                    }
                    else
                    {
                        alert("验证码有误！");
                    }
                }
                else
                {
                    alert("请求失败"+request.status);
                }
            }
        }
        request.send(message);
    }
    send_code.onclick=function(){
        var request=new XMLHttpRequest();
        request.open("POST","i/noteuser/noteUser/sendCodeUpdate",true);
        request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        var message="userName="+user;
        request.onreadystatechange=function(){
            if(request.readyState==4)
            {
                if(request.status==200)
                {
                    var data=JSON.parse(request.responseText);
                    if(data.result==1)
                    {
                        alert("发送成功！");
                    }
                }
                else
                {
                    alert("请求失败"+request.status);
                }
            }
        }
        request.send(message);
    }
</script>
</body>
</html>